from django.db import models
import enum

class Status(enum.Enumeration):
    WAIT = enum.Item(0, 'WAIT')
    DOING = enum.Item(1, 'DOING')
    DONE = enum.Item(2, 'DONE')
    FAIL = enum.Item(3, 'FAIL')
    CANCELED = enum.Item(4, 'CANCELED')

# Create your models here.
class Video(models.Model):

    src = models.TextField()
    dst = models.TextField()
    callback_url = models.TextField()
    status_transcode = models.CharField(max_length=20, default=Status.WAIT)
    status_catalog = models.CharField(max_length=20, default=Status.WAIT)
    error = models.TextField()


    def __unicode__(self):
        return '%(id)d'%self.__dict__

class Shot(models.Model):
    video = models.ForeignKey(Video)
    nsec = models.PositiveIntegerField()
    path = models.TextField()

    def __unicode__(self):
        return '%(nsec)d@%(video_id)d'%self.__dict__

    @property
    def as_timecode(self):
        from datetime import timedelta
        return '0'+str(timedelta(seconds=self.nsec))


#.s

'''
from m.models import *
v = Video()
v.save()
v.shot_set.add(Shot(nsec=1,path='a'))
v.shot_set.add(Shot(nsec=1,path='b'))
v.shot_set.add(*[Shot(nsec=i,path='b') for i in range(0,10])
v.shot_set.all()
v.shot_set.filter(nsec__gte=100)
v.shot_set.filter(nsec__gte=100).delete()

v = Video()
v.status_transcode = Status.DOING
v.status_transcode = Status.DOING

'''